package com.tjk.crawler.base.entity;

import com.tjk.crawler.base.enums.ResultStatus;
import lombok.Data;

/**
 * @Author tangjiakai
 * @Date 2024/6/19 11:08
 * @Description: 返回前端统一对象
 */
@Data
public class Result<T> {
    private ResultStatus code; //业务码:不是http状态码  200：成功，-2：失败, -1:未登录
    private String errMsg;// 错误信息，如果业务成功，errMsg为空
    private T data;

    public static <T> Result success(T data) {
        Result<Object> result = new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result fail(String msg) {
        Result<Object> result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(msg);
        return result;
    }

    public static Result fail(ResultStatus resultStatus, String msg) {
        Result<Object> result = new Result<>();
        result.setCode(resultStatus);
        result.setErrMsg(msg);
        return result;
    }
}
